package com.example.admin_oa.controller;

import com.example.admin_oa.model.mapper.SysPermissionMapper;
import com.example.admin_oa.model.service.SysPermissionService;
import com.example.comment_oa.pojos.SysPermission;
import com.example.comment_oa.response.AjaxResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("adminOa/permi")
@CrossOrigin
public class PermissionController {
    @Resource
    SysPermissionMapper sysPermissionMapper;
    @Resource
    SysPermissionService sysPermissionService;

    @PostMapping("select")
    public AjaxResponse select(){
        List<SysPermission> meuList = sysPermissionService.menuListAll();
        return AjaxResponse.success(meuList);
    }

    @PostMapping("selectYes")
    public AjaxResponse selectYes(){
        List<SysPermission> sysPermissions = sysPermissionService.menuYes();
        return AjaxResponse.success(sysPermissions);
    }

    @PostMapping("selectByRol/{roleId}")
    public AjaxResponse sele(@PathVariable("roleId")int roleId){
        return AjaxResponse.success(sysPermissionService.map(roleId));
    }

    @PostMapping("add")
    public AjaxResponse add(@RequestBody SysPermission sysPermission){
        return AjaxResponse.success(sysPermissionService.add(sysPermission));
    }

    @PostMapping("down")
    public AjaxResponse down(@RequestBody SysPermission sysPermission){
        System.out.println(sysPermission);
        return AjaxResponse.success(sysPermissionMapper.updateById(sysPermission));
    }

}
